package cn.edu.zut;

import cn.edu.zut.mapper.UserMapper;
import cn.edu.zut.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

/**
 * @author Davey chan
 */
public class Mybatisdemo {
    public static void main(String[] args) throws Exception {
//        加载核心
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
//      获取sql session对象,用它来执行
        SqlSession sqlSession = sqlSessionFactory.openSession();
//        执行sql
//        List<User> users = sqlSession.selectList("test.selectAll");
//        获取userMapper的代理对象
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        List<User> users=userMapper.selectAll();



        System.out.println(users);
        sqlSession.close();
    }
}
